/**
 * Created by ZFL on 2017/12/26.
 */
var PageInit = function () {
    if($.getPara('type')!=""){
        message();
    }
};
var pageNum=1;
var pageSize=10;
function message() {
    $.ajaxHandler({
        model: function () {
            var obj = {};
            obj.pageNum=pageNum;
            obj.pageSize=pageSize;
            obj.type=$.getPara('type');
            obj.userId = com_obj.userId;
            return obj;
        },
        visible: true,
        visibleTime: 500,
        approve: true,
        api: "yg_baijiaapp/pushMessage/getUserMessage",
        success: function (result) {
            //console.log(result);
            if (result.code == 10000) {
                var data=result.data;
                if(data.length>0){
                    var html='';
                    $.each(data,function (index,item) {
                        html+='<li>';
                        html+=' <div class="system-tex">';
                        if(item.type==0){//系统消息
                            html+=' <div class="system-pic"><img src="../src/images/message/system_message.png" /></div>';
                            html+='  <div class="sy-mg"><h2>系统消息</h2><p>'+item.createTime+'</p></div>';
                        }else if(item.type==1){//钱包消息
                            html+='<div class="system-pic"><img src="../src/images/message/my_purse.png" /></div>';
                            html+='<div class="sy-mg"><h2>钱包消息</h2><p>'+item.createTime+'</p></div>';
                        }else if(item.type==2){//物流消息
                            html+='<div class="system-pic"><img src="../src/images/message/logistics_inform.png" /></div>';
                            html+='<div class="sy-mg"><h2>物流消息</h2><p>'+item.createTime+'</p></div>';
                        }
                        html+='</div>';
                        html+='<div class="sy-mg-tex">'+item.content+'</div>';
                        html+='   </li>';
                    });
                    if($.getPara('type')==0){//系统消息
                        document.title='系统消息';
                        $(".sys-mag").show().html(html);
                    }else if($.getPara('type')==1){//钱包消息
                        document.title='我的钱包';
                        $(".purse-mag").show().html(html);
                    }else if($.getPara('type')==2){//物流消息
                        document.title='物流消息';
                        $(".logistics-mag").show().html(html);
                    }
                }else{
                    if(pageNum>1){
                        $("body").destroyInfinite();
                    }
                }
            } else {
                $.toast("加载失败", "text");
            }
        }
    });
}

//滚动加载
var loading=false;
function infinite() {
    $("body").infinite().on("infinite", function () {
        if (loading) return;
        // 设置flag
        loading = true;
        $('.weui-infinite-scroll-box').show();
        setTimeout(function () {
            pageNum++;
            loading = false;
            $('.weui-infinite-scroll-box').hide();
            message();//系统消息
        }, 1000);

    });
}
